<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
    <div id='app'>
        {{msg}}

        <form action="">
            请输入id <input type="text" name="" id="" v-model='formData.id'>
            请输入姓名 <input type="text" name="" id="" v-model='formData.name'>
            请输入年纪<input type="text" name="" id="" v-model='formData.age'>
            <input type='button' value='添加用户' @click='add'>
        </form>
        <ul>
            <li v-for="(item, index) in arr" :key="index">
                {{item.id}}===={{item.name}}==={{item.age}}
            </li>
        </ul>
    </div>
    <script type='text/javascript'>
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue',
                arr:[
                    {id:1,name:'jack',age:11},
                    {id:2,name:'jack',age:12},
                    {id:3,name:'jack3',age:13},
                ],
                formData:{
                    id:'',
                    name:'',
                    age:''
                }
            },
            methods:{
                add(){
                    /* 
                    1、判断表单是否有值
                    2、获取表单数据
                    3、将表单数据添加数组中
                    */
                   if(this.formData.id.trim().length<=0 || this.formData.name.trim().length<=0  || this.formData.age.trim().length<=0 ){
                       return ;
                   }
                   console.log(this.formData);
                  // var aa=this.formData
                    //   lodash
                //    this.arr.push(aa)
                this.arr=[...this.arr,...[this.formData]]

                   //this.formData.id=this.formData.name=this.formData.age=''
                }
                
            }
        });
    </script>
</body>
</html>